<template>
  <view>
    <u-tabbar
      :height="110"
      v-model="current"
      :list="list"
      active-color="#02af74"
      :before-switch="beforeSwitch"
      @change="uTabbarM"
    ></u-tabbar>
  </view>
</template>

<script lang='ts' >
import { Component, Prop, Vue, Watch, Emit } from "vue-property-decorator";

// import uTabbar from "@/uview-ui/components/u-tabbar/u-tabbar.vue";
import { AppModule } from "../../store/modules/app";

@Component({
  //   @Component  是一个装修器   不可以在下面写语句
  name: "bar",
})
export default class extends Vue {
  @Prop({
    type: String, // 父组件传递给子组件的数据类型
    required: false, // 是否必填
    default: " ", // 默认值， 如果传入的是 Object，则要 default: ()=>({}) 参数为函数
  })
  msg!: string;

  list = [
    {
      iconPath: "home",
      selectedIconPath: "home-fill",
      text: "首页",
      pagePath: "pages/home/home",
      // count: 2,
      // isDot: true,
      customIcon: false,
    },
    {
      iconPath: "calendar-fill",
      selectedIconPath: "calendar-fill",
      text: "统计",
      pagePath: "pages/stati/index",
      customIcon: false,
    },
    {
      iconPath: "list",
      selectedIconPath: "list",
      pagePath: "pages/equipment/index",
      text: "设备",
      customIcon: false,
    },
    // {
    // 	iconPath: "https://cdn.uviewui.com/uview/common/min_button.png",
    // 	selectedIconPath: "https://cdn.uviewui.com/uview/common/min_button_select.png",
    // 	text: '发布',
    // 	midButton: true,
    // 	customIcon: false,
    // },
    {
      iconPath: "car-fill",
      selectedIconPath: "car-fill",
      pagePath: "pages/cargo/index",
      text: "铺货",
      customIcon: false,
    },
    {
      iconPath: "account",
      selectedIconPath: "account-fill",
      pagePath: "pages/my/index",
      text: "个人",
      // count: 23,
      isDot: false,
      customIcon: false,
    },
  ];

  current = AppModule.selectBar;

  public selectA: any = "9";

  created() {
    console.log(AppModule, "AppModule");
    console.log(this.current, "current");
  }

  mounted() {
    //  console.log('父组件传递的参数:',this.$parent)   //暂时不考虑
  }

  uTabbarM() {
    console.log("uTabbarM改变");
  }

  beforeSwitch(index: any) {
    console.log(index, "点击", this.selectA, AppModule.selectBarS);

    this.selectA = index;

    if (this.selectA !== AppModule.selectBarS) {
      // this.selectA=index

      AppModule.selectBarSAction(index);

      if (index == 1) {

        uni.switchTab({
          url: "../../pages/home/home",
        });

        // uni.navigateTo({
        //   url: "../stati/index",
        // });

        return true;
      } else if (index == 0) {
        uni.navigateTo({
          url: "../home/home",
        });
        return true;
      } else if (index == 2) {
        uni.navigateTo({
          url: "../equipment/index",
        });
        return true;
      } else if (index == 3) {
        uni.navigateTo({
          url: "../cargo/index",
        });
        return true;
      } else if (index == 4) {
        uni.setStorageSync("myOnce", true);
        console.log("wan c444");

          uni.switchTab({
          url: "../my/index",
        });

        // uni.navigateTo({
        //   url: "../my/index",
        // });
        return true;
      }
    } else {
      console.log("不可以点击了");
    }
  }
  //    aaa(index:any){
  // }
}
</script>

<style  lang="scss"  scoped>
</style>